package practicedemo22;

import java.util.Scanner;

public class practicedemo22 {
    //1.输入评委人数，并依次录入评委给的分数，并求出去掉一个最高分、最低分后的平均分
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入评委数量：");
        int n = sc.nextInt();
        double x[] = new double[n];
        for (int i = 0; i < n; i++) {
            System.out.print("请输入第"+(i+1)+"位评委得分：");
            x[i] = sc.nextDouble();
        }
        System.out.println();
        System.out.print("选手最终得分为：");
        System.out.println(averange(x));
    }

    //找出最大得分和最小得分的和
    public static double score(double x[]){
        double max;
        double min;
        max = x[0];
        min = x[0];
        for (int i = 1; i < x.length; i++) {
            max = max > x[i] ? max : x[i];
        }
        for (int i = 1; i < x.length; i++) {
            min = min < x[i] ? min : x[i];
        }
        return max+min;
    }
    //求和函数
    public static double max(double x[]){
        double total = 0;
        for (int i = 0; i < x.length; i++) {
            total += x[i];
        }
        return total;
    }
    //求均值函数
    public static double averange(double x[]){
        return (max(x) - score(x))/(double) (x.length - 2);
    }
}
